package com.example.idachuappone.index.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.idachuappone.R;
import com.example.idachuappone.promptly.entity.Addresses;

public class AddressWebAdapter extends BaseAdapter {
	private Context context;
	private List<Addresses> list;

	private class ViewHolder {
		TextView tv1;
		TextView tv2;

		private ViewHolder() {
		}
	}

	public void setList(List<Addresses> list) {
		this.list = list;
	}

	public AddressWebAdapter(Context context) {
		this.context = context;
	}

	@Override
	public int getCount() {
		return this.list == null ? 0 : this.list.size();
	}

	@Override
	public Object getItem(int position) {
		return this.list == null ? null : (Addresses) this.list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		if (convertView == null) {
			convertView = LinearLayout.inflate(this.context, R.layout.simple_address_web, null);
			viewHolder = new ViewHolder();
			viewHolder.tv1 = (TextView) convertView.findViewById(R.id.textView1);
			viewHolder.tv2 = (TextView) convertView.findViewById(R.id.textView2);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		Addresses pos = this.list.get(position);
		viewHolder.tv1.setText(pos.getArea() + pos.getCommunity());
		viewHolder.tv2.setText(pos.getName());
		return convertView;
	}
}
